﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace org.mayb.Fixtures
{
    public class ObjectInfo
    {
        public string ID { get; set; }
        public string Type { get; set; }

        public string File { get; set; }
        public int Line { get; set; }
        public int Char { get; set; }

        public List<string> References
        {
            get
            {
                return this.Properties.FindRefernces();
            }
        }

        public PropertyHash Properties { get; set; }

        public object BuildObject()
        {
            Type objectType = Fixtures.FindType(this.Type);
            if(objectType == null)
                throw new Exception("Unable to find type " + this.Type);
            object obj = Fixtures.CreateInstance(objectType);

            try
            {
                this.Properties.ProcessHash(obj, objectType);
            }
            catch (Exception ex)
            {
                throw new FixtureException(string.Format("{0} - {1}@{2}:{3}", ex.Message, this.File, this.Line, this.Char), ex);
            }
            return obj;
        }
    }
}
